package com.bcn.login_mybatisplus_demo.item.controller;

import java.util.AbstractMap;
import java.util.List;

import com.bcn.login_mybatisplus_demo.common.controller.BaseController;
import com.bcn.login_mybatisplus_demo.common.page.TableDataInfo;
import com.bcn.login_mybatisplus_demo.item.domain.TAppItem;
import com.bcn.login_mybatisplus_demo.item.service.ITAppItemService;
import com.bcn.login_mybatisplus_demo.pojo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 物品Controller
 * 
 * @author administrator
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/system/item")
public class TAppItemController extends BaseController
{
    private String prefix = "system/item";

    @Autowired
    private ITAppItemService tAppItemService;

    @GetMapping()
    public String item()
    {
        return prefix + "/item";
    }

    /**
     * 查询物品列表
     */
    @GetMapping("/list")
    public TableDataInfo list( TAppItem tAppItem)
    {
        startPage();
        List<TAppItem> list = tAppItemService.selectTAppItemList(tAppItem);
        return getDataTable(list);
    }

    /**
     * 新增物品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物品
     */
    @PostMapping("/add")
    public R addSave(@RequestBody TAppItem tAppItem)
    {
        return R.success(tAppItemService.insertTAppItem(tAppItem));
    }

    /**
     * 修改物品
     */
    @GetMapping("/edit/{itemId}")
    public String edit(@PathVariable("itemId") Long itemId, ModelMap mmap)
    {
        TAppItem tAppItem = tAppItemService.selectTAppItemById(itemId);
        mmap.put("tAppItem", tAppItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存物品
     */
    @PostMapping("/edit")
    public R editSave(@RequestBody TAppItem tAppItem)
    {
        return R.success(tAppItemService.updateTAppItem(tAppItem));
    }

    /**
     * 删除物品
     */
    @GetMapping( "/remove/{id}")
    public R remove(@PathVariable("id")  Integer id)
    {
        return R.success(tAppItemService.deleteTAppItemById(id.longValue()));
    }
}
